package com.accp.vehiclecare.biz.syhbiz;

import com.accp.vehiclecare.dao.syhdao.IEndcheckDAO;
import com.accp.vehiclecare.dao.syhdao.RepairbillMapper;
import com.accp.vehiclecare.pojo.Endcheck;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class EndcheckBiz {

    @Resource
    private IEndcheckDAO eDao;

    @Resource
    private RepairbillMapper rDao;


    @Transactional(propagation = Propagation.REQUIRED)
    public void jg(Endcheck endcheck){
        if (eDao.insert(endcheck) > 0){
            if (endcheck.getChecktype() == 0){
                rDao.updateZt(endcheck.getRepairbillsno(),4,new Date());
            }else if (endcheck.getChecktype() == 1){
                rDao.updateZt(endcheck.getRepairbillsno(),6,new Date());
            }
        }
    }

    public Integer countRework(String billNo){
        QueryWrapper qw= Wrappers.query();
        qw.eq("repairbillsno",billNo);
        qw.eq("checktype",1);
        return eDao.selectCount(qw);
    }
}
